package com.itheima.web.manager;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.itheima.domain.db.Admin;
import com.itheima.service.db.AdminService;
import com.itheima.util.ResultInfo;
import com.itheima.web.exception.CustomException;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

@Component
public class LoginManager {

    @DubboReference
    private AdminService adminService;

    //登陆
    public ResultInfo login(String username, String password) {
        //MD5加密密码
        String md5 = SecureUtil.md5(password);
        //1.rpc调用service查询
       Admin admin=adminService.userLogin(username,md5);
       //2.判断用户是否为空
        if (admin==null){
            throw new CustomException("用户名或密码错误");
        }
        //3.返回结果
        return ResultInfo.success(admin);
    }
}
